package com.saas.datasource.core;


public class DynamicDataSourceContextHolder {

	// 定义一个ThreadLocal变量，保存数据源类型（保证线程安全，多个线程之间互不影响）
	private static final ThreadLocal<String> DATA_SOURCE_CONTEXT_HOLDER = new ThreadLocal<>();
	public static final String DEFAULT_DATA_SOURCE = "master";
	static {
		setDefaultDataSource(); // 默认指定主库
	}
	public static void setDefaultDataSource() {
		DATA_SOURCE_CONTEXT_HOLDER.set(DEFAULT_DATA_SOURCE);
	}

	public static void setDataSource(String dataSourceEnum) {
		DATA_SOURCE_CONTEXT_HOLDER.set(dataSourceEnum);
	}

	public static String getDataSource() {
		return DATA_SOURCE_CONTEXT_HOLDER.get();
	}

}